package com.nzd.slsharing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nzd.slsharing.mapper.LearningExchangeMapper;
import com.nzd.slsharing.pojo.LearningExchange;
import com.nzd.slsharing.service.LearningExchangService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

@Service
@Transactional
public class LearningExchangeServiceImpl extends ServiceImpl<LearningExchangeMapper, LearningExchange> implements LearningExchangService {


    /**
     * 分页获取所有学习交流帖子（带条件）
     *
     * @param pageParam
     * @param name
     */
    @Override
    public IPage<LearningExchange> getUsersLearningExchangS(Page<LearningExchange> pageParam, String name) {
        LambdaQueryWrapper<LearningExchange> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LearningExchange::getName, name);
        if(!StringUtils.isEmpty(name)){
            wrapper.like(LearningExchange::getName, name);
        }
        //按创建时间降序
        wrapper.orderByDesc(LearningExchange::getCreateTime);
        return baseMapper.selectPage(pageParam, wrapper);
    }

    /**
     * 分页获取所有学习交流帖子（不带条件）
     *
     * @param pageParam
     */
    @Override
    public IPage<LearningExchange> getUsersLearningExchangS(Page<LearningExchange> pageParam) {
        LambdaQueryWrapper<LearningExchange> wrapper = new LambdaQueryWrapper<>();
        //按创建时间降序
        wrapper.orderByDesc(LearningExchange::getCreateTime);
        return baseMapper.selectPage(pageParam, wrapper);
    }
}
